VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmExportApproved 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Export approved data"
   ClientHeight    =   4500
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8550
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4500
   ScaleWidth      =   8550
   Begin VB.Frame Frame1 
      Caption         =   "Email"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1215
      Left            =   2640
      TabIndex        =   14
      Top             =   2400
      Width           =   5295
      Begin VB.CheckBox chkCC 
         Caption         =   "long.nguyen@galileovietnam.com"
         Enabled         =   0   'False
         Height          =   495
         Left            =   1320
         TabIndex        =   16
         Top             =   600
         Width           =   3735
      End
      Begin VB.CheckBox chkSendTo 
         Caption         =   "acctsgn@galileovietnam.com"
         Height          =   375
         Left            =   1320
         TabIndex        =   15
         Top             =   240
         Width           =   3855
      End
      Begin VB.Label Label5 
         Caption         =   "Carbon copy:"
         Height          =   375
         Left            =   240
         TabIndex        =   18
         Top             =   720
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Send to:"
         Height          =   255
         Left            =   600
         TabIndex        =   17
         Top             =   360
         Width           =   735
      End
   End
   Begin VB.CommandButton cmdExportapprovedtoweb 
      Caption         =   "Export approved to web"
      Height          =   375
      Left            =   4560
      TabIndex        =   13
      Top             =   3840
      Width           =   1935
   End
   Begin VB.CommandButton cmdImport 
      Caption         =   "To &Import"
      Height          =   375
      Left            =   4560
      TabIndex        =   8
      Top             =   3840
      Width           =   1695
   End
   Begin VB.CheckBox chkCompress 
      Caption         =   "Compress the file after exporting"
      Enabled         =   0   'False
      Height          =   255
      Left            =   4680
      TabIndex        =   7
      Top             =   840
      Width           =   2895
   End
   Begin VB.CommandButton Command4 
      Caption         =   "..."
      Enabled         =   0   'False
      Height          =   375
      Left            =   7680
      TabIndex        =   6
      Top             =   1200
      Width           =   375
   End
   Begin VB.TextBox txtPath 
      Height          =   315
      Left            =   4680
      TabIndex        =   5
      Text            =   "c:\"
      Top             =   1200
      Width           =   2895
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   4800
      Top             =   240
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdViewFolder 
      Caption         =   "View exported folder"
      Height          =   375
      Left            =   2640
      TabIndex        =   4
      Top             =   3840
      Width           =   1695
   End
   Begin VB.CommandButton Command2 
      Caption         =   "&Close"
      Height          =   375
      Left            =   6840
      TabIndex        =   3
      Top             =   3840
      Width           =   1095
   End
   Begin VB.CommandButton cmdExport 
      Caption         =   "To &Export"
      Height          =   375
      Left            =   4560
      TabIndex        =   2
      Top             =   3840
      Width           =   1695
   End
   Begin VB.ComboBox cboOffice 
      Height          =   315
      ItemData        =   "frmExportApproved.frx":0000
      Left            =   4680
      List            =   "frmExportApproved.frx":0013
      Sorted          =   -1  'True
      TabIndex        =   1
      Text            =   "SGN"
      Top             =   1800
      Width           =   2895
   End
   Begin VB.Label lblDate 
      Caption         =   "November,17 2008"
      Height          =   375
      Left            =   240
      TabIndex        =   12
      Top             =   2520
      Width           =   2175
   End
   Begin VB.Label lblVersion 
      Caption         =   "Version 1.0"
      Height          =   255
      Left            =   240
      TabIndex        =   11
      Top             =   2220
      Width           =   2055
   End
   Begin VB.Label Label3 
      Caption         =   "Import/Export"
      Height          =   255
      Left            =   240
      TabIndex        =   10
      Top             =   1920
      Width           =   2055
   End
   Begin VB.Image Image1 
      Height          =   1440
      Left            =   240
      Picture         =   "frmExportApproved.frx":0030
      Top             =   240
      Width           =   1440
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "Save to"
      Height          =   375
      Left            =   2760
      TabIndex        =   9
      Top             =   1200
      Width           =   1695
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      Caption         =   "Which office is exported?"
      Height          =   255
      Left            =   2400
      TabIndex        =   0
      Top             =   1800
      Width           =   2055
   End
End
Attribute VB_Name = "frmExportApproved"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public WhoCall As String
Dim sql As String
Dim strLine As String

Private Sub cboOffice_Click()
    chkSendTo.Value = vbUnchecked
    If cboOffice = "SGN" Then
        chkSendTo.Caption = "acctsgn@galileovietnam.com"
    ElseIf cboOffice = "IND" Then
        chkSendTo.Caption = "finance@galileovietnam.com"
    ElseIf cboOffice = "HAN" Then
        chkSendTo.Caption = "accthan@galileovietnam.com"
    ElseIf cboOffice = "VTE" Then
        chkSendTo.Caption = "galileo@galileolaos.com"
    Else
        chkSendTo.Caption = "acctpnh@galileocambodia.com"
    End If
    
End Sub

Private Sub chkCC_Click()
    If chkCC.Value = vbChecked Then
        eaEmailCC = Trim(chkCC.Caption)
    Else
        eaEmailCC = ""
    End If
End Sub

Private Sub chkSendTo_Click()
    If chkSendTo.Value = vbChecked Then
        chkCC.Enabled = True
        eaEmailSendto = Trim(chkSendTo.Caption)
    Else
        eaEmailSendto = ""
        chkCC.Value = vbUnchecked
        chkCC.Enabled = False
    End If
End Sub

Private Sub cmdExport_Click()
    Dim sql As String
    Dim rs As New ADODB.Recordset
    'Call KetNoi
    If Trim(cboOffice.Text) = "" Then
        MsgBox "Please select an office to export", vbInformation + vbOKOnly, "Export approved data"
        Exit Sub
    End If
    'sql = "Select * from approved where isApproved ='1' and office ='" & cboOffice.Text & "'"
    sql = "Select * from approved where office ='" & cboOffice.Text & "'"
    Set rs = adoConnection.Execute(sql)
    path_fileExport = txtPath.Text & "\Approved_data_for_" & UCase(cboOffice.Text) & ".dat" '"_" & Day(Date) & Left(MonthName(Month(Date)), 3) &
    Open path_fileExport For Output As #1
        While Not rs.EOF
            If Trim(GetFieldValue(rs.Fields("isApproved"))) = "" Then
                Print #1, GetFieldValue(rs.Fields("IMnumber")) & "~" & GetFieldValue(rs.Fields("Office")) & "~" & GetFieldValue(rs.Fields("InvoiceME")) & "~0"
            Else
                Print #1, GetFieldValue(rs.Fields("IMnumber")) & "~" & GetFieldValue(rs.Fields("Office")) & "~" & GetFieldValue(rs.Fields("InvoiceME")) & "~" & GetFieldValue(rs.Fields("isApproved"))
            End If
            rs.MoveNext
        Wend
    Close #1
    rs.Close
    Set rs = Nothing
    Call ZipFile(path_fileExport, "", True, " a -ep ", False, "")
    
    'tranfer file .rar to web
    path_fileExport = Replace(path_fileExport, ".dat", ".rar")
    'Call DisconnectDB
    MsgBox "Export is successful", vbInformation + vbOKOnly, "Export approved data"
End Sub

Private Sub cmdExportapprovedtoweb_Click()
    Dim sql As String
    Dim rs As New ADODB.Recordset
    Me.Hide
    'Call KetNoi
    If Trim(cboOffice.Text) = "" Then
        MsgBox "Please select an office to export", vbInformation + vbOKOnly, "Export approved data to web"
        Exit Sub
    End If
    'sql = "Select * from approved where isApproved ='1' and office ='" & cboOffice.Text & "'"
    sql = "Select * from approved where office ='" & cboOffice.Text & "'"
    Set rs = adoConnection.Execute(sql)
    
    path_fileExport = App.Path & "\Export" & "\Approved_data_for_" & UCase(cboOffice.Text) & ".dat" '& "_" & Day(Date) & Left(MonthName(Month(Date)), 3)
    
    Open path_fileExport For Output As #1
        While Not rs.EOF
            If Trim(GetFieldValue(rs.Fields("isApproved"))) = "" Then
                Print #1, GetFieldValue(rs.Fields("IMnumber")) & "~" & GetFieldValue(rs.Fields("Office")) & "~" & GetFieldValue(rs.Fields("InvoiceME")) & "~0"
            Else
                Print #1, GetFieldValue(rs.Fields("IMnumber")) & "~" & GetFieldValue(rs.Fields("Office")) & "~" & GetFieldValue(rs.Fields("InvoiceME")) & "~" & GetFieldValue(rs.Fields("isApproved"))
            End If
            rs.MoveNext
        Wend
    Close #1
    rs.Close
    Set rs = Nothing
    'Call DisconnectDB
    
    '<Commands Winrar>
    'a Add files to archive
    'ep Exclude paths from names
    Call ZipFile(path_fileExport, "", True, " a -ep ", False, "")
    
    'tranfer file .rar to web
    path_fileExport = Replace(path_fileExport, ".dat", ".rar")
    
    eaok = chkSendTo.Value ' kiem tra co check gui mail khong?
  
    Call MDIForm1.connectURL
    'MsgBox "Export is successful", vbInformation + vbOKOnly, "Export approved data"
    Unload Me
End Sub

Private Sub cmdImport_Click()
    Call importapprovedata
End Sub



Public Sub importapprovedata()
    Dim fileImportName As String
'''    Dim sql As String
    Dim isChecked As Boolean
    If frmExportApproved.WhoCall = "ImportfromFile" Then
        fileImportName = txtPath.Text
    ElseIf frmExportApproved.WhoCall = "ImportfromWeb" Then
        fileImportName = App.Path & "\import\" & path_fileExport
    ElseIf frmExportApproved.WhoCall = "ImportAllfilefromWeb" Then
        fileImportName = App.Path & "\import\" & path_fileExport
    End If
    
    Open fileImportName For Input As #1
        isChecked = False
        Do While Not EOF(1)
            Line Input #1, strLine
            If Not isChecked Then
                If isRightFormatImportApprovedData(strLine) Then
                    isChecked = True
                Else
                    MsgBox "Wrong data format, please select another file", vbInformation + vbOKOnly, "Import approved data"
                    Close #1
                    Exit Sub
                End If
            End If
            

            sql = ""
            If GetApprovedData(strLine, 3) = "I" Then
                 If GetApprovedData(strLine, 4) = "1" Then
                    sql = "update detail set Approved ='1' where inumber='" & GetApprovedData(strLine, 1) & "' and OFFICE='" & GetApprovedData(strLine, 2) & "'"
                 ElseIf GetApprovedData(strLine, 4) = "0" Then
                    sql = "update detail set Approved ='0' where inumber='" & GetApprovedData(strLine, 1) & "' and OFFICE='" & GetApprovedData(strLine, 2) & "'"
                 End If
            ElseIf GetApprovedData(strLine, 3) = "M" Then
                If GetApprovedData(strLine, 4) = "1" Then
                    sql = "update MoneyExchange set Approved ='1' where mnumber='" & GetApprovedData(strLine, 1) & "' and OFFICE='" & GetApprovedData(strLine, 2) & "'"
                ElseIf GetApprovedData(strLine, 4) = "0" Then
                    sql = "update MoneyExchange set Approved ='0' where mnumber='" & GetApprovedData(strLine, 1) & "' and OFFICE='" & GetApprovedData(strLine, 2) & "'"
                End If
            Else
                MsgBox "Wrong data format!", vbCritical + vbOKOnly, "Error"
                Exit Sub
            End If

            If Len(sql) > 0 Then
                adoConnection.Execute (sql)
            End If
        Loop
    Close #1
    Call FileSystem.Kill(fileImportName)
    MsgBox "Import is successful", vbInformation + vbOKOnly, "Import approved data"
End Sub

Private Function GetApprovedData(str As String, NumberOfData As Integer) As String
    Dim I As Integer
    Dim numberofSpecial As Integer
    Select Case NumberOfData
        Case 1
            GetApprovedData = Left(str, InStr(1, str, "~", vbTextCompare) - 1)
        Case 2
            GetApprovedData = Mid(str, InStr(1, str, "~", vbTextCompare) + 1, InStr(InStr(1, str, "~", vbTextCompare) + 1, str, "~") - InStr(1, str, "~", vbTextCompare) - 1)
        Case 3
            numberofSpecial = 0
            For I = 1 To Len(str)
                If Mid(str, I, 1) = "~" Then
                    numberofSpecial = numberofSpecial + 1
                End If
                If numberofSpecial = NumberOfData Then
                    GetApprovedData = Mid(str, I - 1, 1)
                    Exit Function
                End If
            Next I
        Case 4
             GetApprovedData = Right(str, 1)
        Case Else
            MsgBox "Wrong paramater"
            End
    End Select
End Function

Private Sub cmdViewFolder_Click()
    Shell "explorer.exe " & txtPath.Text, vbMaximizedFocus
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

Private Function isRightFormatImportApprovedData(strData As String) As Boolean
    Dim str As String
    Dim numberofSpecial As Integer
    Dim I As Integer
    str = strData
    numberofSpecial = 0
    For I = 1 To Len(str)
        If Mid(str, I, 1) = "~" Then
            numberofSpecial = numberofSpecial + 1
        End If
    Next I
    If numberofSpecial = 3 Then
        isRightFormatImportApprovedData = True
    Else
        isRightFormatImportApprovedData = False
    End If
End Function

Private Sub Command4_Click()
    With CommonDialog1
        .InitDir = txtPath.Text
        .ShowOpen
        txtPath.Text = .Filename
        If Len(txtPath.Text) > 0 Then
            cmdImport.Enabled = True
        End If
    End With
End Sub

Private Sub Form_Load()
    Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
    lblVersion.Caption = "Version " & currVer
    lblDate.Caption = "Date: " & verdate
    If WhoCall = "ExporttoFile" Then
        cmdImport.Visible = False
        cmdExportapprovedtoweb.Visible = False

        cmdExport.Visible = True

        Me.Caption = "Export approved data to file"
    
    ElseIf WhoCall = "ImportfromFile" Then
        cmdExport.Visible = False
        cmdExportapprovedtoweb.Visible = False
        cmdViewFolder.Visible = False

        cmdImport.Visible = True
        Command4.Enabled = True
        Label1.Visible = False
        Label2.Visible = False
        cboOffice.Visible = False
        Me.Caption = "Import approved data from file"

    ElseIf WhoCall = "ExporttoWebforGM" Then
        cmdExport.Visible = False
        cmdImport.Visible = False
        Command4.Visible = False

        txtPath = "Web"
        txtPath.Enabled = False
        cmdViewFolder.Visible = False
        
        cmdExportapprovedtoweb.Visible = True
        Me.Caption = "Export approved data to Web"
    Else
        MsgBox "I do not know what I have to do!", vbCritical + vbOKOnly, "Error"
        Unload Me
    End If
    eaEmailCC = ""
    eaEmailSendto = ""
    chkCC.Caption = email
End Sub

